const mongoose = require('mongoose');
// 创建Schema对象
const Schema = mongoose.Schema
var schema = new Schema({
    name: {
        type: String,
        // default: 'female', //默认为female
    },
    parent: { type: mongoose.SchemaTypes.ObjectId, ref: "Category" }
});

schema.virtual('children', {
    localField: '_id',
    foreignField: "parent",
    justOne: false,
    ref: 'Category'
})

schema.virtual('newsList', {
    localField: '_id',
    foreignField: "categories",
    justOne: false,
    ref: 'Article'
})

// exports.model = stuModel
module.exports = mongoose.model('Category', schema);